package com.woniu40.petai_manager.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu40.petai_manager.entity.Article;
import com.woniu40.petai_manager.mapper.ArticleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;


@Service
public class ArticleService {

    @Autowired
    ArticleMapper articleMapper;

    public int addArticle(Article article) {
        article.setCreateTime(new Date());
        return articleMapper.insert(article);
    }

    public Article exploreArticle(Integer articleId) {
        return articleMapper.selectByPrimaryKey(articleId);
    }

    public PageInfo<Article> listArticles(Integer pageNum, Integer pageSize, String keyword) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(articleMapper.selectRegexpArticle(keyword));
    }

    public int removeArticle(Integer articleId) {
        return articleMapper.deleteByPrimaryKey(articleId);

    }

    public int updateArticle(Article article) {
        return articleMapper.updateOnQuill(article.getArticleId(),article.getArticleTitle(),article.getManagerId(),article.getArtTypeId(),article.getArticleLabel(),article.getArticleContent(),article.getArticleStatus());
    }
}